/*
 * @Author: w
 * @Date: 2022-02-18 14:31:24
 * @Description: 剑指 Offer 09. 用两个栈实现队列
 */

/* 
队列只有 pop push方法 length属性
保证顺序下，入栈 移出 出栈
*/

var CQueue = function () {
  // 仅 push pop
  this.stack1 = [];
  this.stack2 = [];
};

/**
 * @param {number} value
 * @return {void}
 */
CQueue.prototype.appendTail = function (value) {
  this.stack1.push(value);
  return null;
};

/**
 * @return {number}
 */
CQueue.prototype.deleteHead = function () {
  if (this.stack2.length) {
    return this.stack2.pop();
  }
  if (this.stack1.length) {
    while (this.stack1.length) {
      this.stack2.push(this.stack1.pop());
    }
  }
  if (this.stack2.length) {
    return this.stack2.pop();
  }
  return -1;
};

/**
 * Your CQueue object will be instantiated and called as such:
 * var obj = new CQueue()
 * obj.appendTail(value)
 * var param_2 = obj.deleteHead()
 */
